package com.bsj.pay.util.security;

import java.util.Random;
import java.util.UUID;
 
public class PassWrodsCreater {
 
	public static String generatePassword (int length) {
        // 最终生成的密码
        String password = "";
        Random random = new Random();
        for (int i = 0; i < length; i ++) {
            // 随机生成0或1，用来确定是当前使用数字还是字母 (0则输出数字，1则输出字母)
            int charOrNum = random.nextInt(2);
            if (charOrNum == 1) {
                // 随机生成0或1，用来判断是大写字母还是小写字母 (0则输出小写字母，1则输出大写字母)
                int temp = random.nextInt(2) == 1 ? 65 : 97;
                password += (char) (random.nextInt(26) + temp);
            } else {
                // 生成随机数字
                password += random.nextInt(10);
            }
        }
        return password;
    }
	
	public static String generateRandomNumber(int length) {
        // 最终生成的密码
		 String charList = "0123456789";
	     String rev = "";
	     Random f = new Random();
	     for(int i=0;i<length;i++)
	     {
	        rev += charList.charAt(Math.abs(f.nextInt())%charList.length());
	     }
	     return rev;
    }
	
	 public static String getUUIDStr() {
	        String s = UUID.randomUUID().toString();
	        //去掉“-”符号
	        return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
	 }
	
	 public static String getUUID() {
	        //随机生成一位整数
	        int random = (int) (Math.random() * 9 + 1);
	        String valueOf = String.valueOf(random);
	        //生成uuid的hashCode值
	        int hashCode = UUID.randomUUID().toString().hashCode();
	        //可能为负数
	        if (hashCode < 0) {
	            hashCode = -hashCode;
	        }
	        return valueOf + String.format("%015d", hashCode);
	    }
	 
	 
	 public static String myEncrypt(String  data){
	        char e[]=data.toCharArray();
	        int a,d,i,j,k;
	        String ls="encry";
	        int n=ls.length()*4;
	        char[] b,c;
	        a=e.length;
	        if((d=a%n)!=0){
	            a = a + n-d;
	        }
	        b = new char[a];
	        k=a/n;
	        for(i=0;i<k;i++){
	            for(j=0;j<n;j++){
	                if(i*n+j<e.length){
	                    b[i+k*j]=e[i*n+j];
	                }else{
	                    b[i+k*j]=' ';
	                }
	            }
	        }
	        while(b[a-1]==' '){
	            a--;
	        }
	        c = new char[a];
	        for(i=0;i<a;i++){
	            c[i]=b[i];
	        }
	        return String.valueOf(c);
	    }
	
	

    public static void main(String[] args) {
    	String ss="alipay_sdk=alipay-sdk-java-4.8.73.ALL&app_id=2017122001013766&biz_content=%7B%22body%22%3A%22%E7%94%B5%E8%B4%B9%22%2C%22enable_pay_channels%22%3A%22balance%2CcreditCard%2CcreditCardExpress%2CcreditCardCartoon%2CdebitCardExpress%2CmoneyFund%2Ccredit_group%2Cpromotion%2Ccoupon%22%2C%22out_trade_no%22%3A%22202109130131706370%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22%E7%BD%91%E4%B8%8A%E5%9B%BD%E7%BD%91%22%2C%22total_amount%22%3A%2210.00%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=https%3A%2F%2Fpayctl.95598pay.com%2Fpayunifycontroller%2Frest%2Fnotice%2Falipay%2Fhandle&return_url=https%3A%2F%2Fsgcpay.95598pay.com%2FsgcPay%2Fpayment%2FaliPayBack.htm&sign=MCXZeJl1D%2BMsKpufLG%2B5hWZ%2BO04VGgOZ0a4wffA3A3fw9iMw8OyfOiX6j%2Fmjlza%2BlSEqYHB92eaQHsqOfczAN5o4l5Erk9QBnq0FGQbb%2BWaOaf4OR1QeYOjjquR0hiD89BHLKLjgOBknMPOqMYsDrx8z62%2FlN%2BhnUzTlgea69%2FFW%2BpjpROsLk1jeZV4bHfHmxus8y%2FtuDY2lAn9HN1CXtn%2BL6eYx2TVXjD8rxhFQaCAF5aI9KsFwBmnko2FaV0XjyvrYHnbH1xJuq5Gb6rmczx2kvWkNwNh4TxOYe%2FqpyMrq%2FyPiV8nkvIW1YTrAo%2FDQ3F1DAe25XiBjLpTGyBOYTA%3D%3D&sign_type=RSA2&timestamp=2021-09-13+23%3A51%3A30&version=1.0";
        System.out.println(PassWrodsCreater.myEncrypt(ss));
    }
 
}
